xlv.obj.processPane={
	extend:function(){
		this.extend('xlv.obj.process');
	},
	implement:function(){
	},
	create:function(tag){
		var div=document.createElement((tag||'div'));
		div.setAttribute('xlvobject','xlv.obj.processPane');
		Element.addClassName(div,'class_processPane');
		return div;			
	},
	properties:{
		zIndex:100,
		paneAlign:'middle', //left right middle,center(if parent is desktop)
		ajaxPane:null,
		modal:false,
		modalOpacity:0.1,
		modalColor:'white',
		disposeWhenHidden:true
	},
	method:{
		construct:function(){
			this.$super('xlv.obj.process.construct');
			Element.addClassName(this,'class_processPane');
			var v=this.$V,p=this.$P;
			if(p.ajaxPane){
				v.pane=document.createElement('div');
				v.pane.setAttribute('id','xlvid_process_pane');
				Element.setStyle(v.pane,{position:'absolute'});
				this.appendChild(v.pane);
				var prop=Object.extend({},(p.ajaxPane.properties||{}));
				prop.autoRequest=false;
				v.pane.appendChild(v.ajaxpane=xlv.sys.newObject('ajaxPane',prop,p.ajaxPane.method));
			}else{
				v.pane=xlv.util.findDirectChild(this,{id:'xlvid_process_pane'});
				if(!v.pane){
					v.pane=document.createElement('div');
					v.pane.setAttribute('id','xlvid_process_pane');
					Element.setStyle(v.pane,{position:'absolute'});
					while(this.firstChild) v.pane.appendChild(this.firstChild);
					this.appendChild(v.pane);
					this.appendChild(v.title);
				}
			}
			this.styleForId(v.pane,v.pane.id);
		},
		initial:function(){
			this.$super('xlv.obj.process.initial');
			this.addEventHandler('xlv:ajax_loaded', '_loadedPane',this.$V.pane);
			if(Prototype.Browser.IE){
				var float=Element.getStyle(this,'float');
				if(float=='left'||float=='right')Element.addClassName(this,'IE_float');
			}
			this.addEventHandler('xlv:dispose','xlv_dispose');
		},
		xlv_dispose:function(event){
			var v=this.$V;
			if(v.ajaxpane && event.memo.src==v.ajaxpane.$V.pane){
				event.stop();
				this.hidePane();
			}
		},
		setModal:function(enable,opacity,color){
			this.$V.modal=enable;
			this._setModal(enable,opacity,color);
		},
		_setModal:function(enable,opacity,color){
			var v=this.$V;
			if((enable &&v.glass)||(enable===false && !v.glass)) return;
			if(enable){
				opacity=(!opacity)?this.$P.modalOpacity:opacity;
				color=(!color)?this.$P.modalColor:color;
				var glass=document.createElement('div');
				this.addEventHandler('mousedown','__glassEvent',glass);
				this.addEventHandler('click','__glassEvent',glass);
				this.addEventHandler('keydown','__glassEvent',glass);
				Element.setStyle(glass, {position:'fixed',left:'0px',top:'0px',right:'0px',bottom:'0px','opacity':opacity,background:color,zIndex:xlv.sys.zIndexModal});
				this.insertBefore(glass,v.pane);
				v.savezIndex=v.pane.style.zIndex;
				Element.setStyle(v.pane,{zIndex:parseInt(xlv.sys.zIndexModal)+1});
				v.glass=glass;
				if(this.$P.modal||this.$V.modal)glass.style.cursor='not-allowed';
			}else{
				this.removeObserve('mousedown','__glassEvent',v.glass);
				this.removeObserve('click','__glassEvent',v.glass);
				this.removeObserve('keydown','__glassEvent',v.glass);
				v.glass.parentNode.removeChild(v.glass);
				v.glass=null;
				v.pane.style.zIndex=v.savezIndex;
			}
		},
		__glassEvent:function(event){
			event.stop();
			if(this.$P.modal||this.$V.modal)return;
			this.hidePane();
		},
		_loadedPane:function(event){
			if(this.$V._redo_showPane){
				this.$V._redo_showPane=false;
				this._showPane();
			}
			this._setModal(true);
			this.loadedPane(event);
		},
		loadedPane:function(event){
		},
		hidePane:function(){
			var v=this.$V;
			if(Element.getStyle(v.pane,'display')!='none'){
				v.pane.style.display='none';
				if(v.ajaxpane&&this.$P.ajaxPane&&this.$P.disposeWhenHidden)this._removeAjaxPane();
				Element.setStyle(this,{zIndex:v.save_zindex});
				this.setModal(false);
			}
		},
		removeAjaxPane:function(){
			this.hidePane();
			this._removeAjaxPane();
		},
		_removeAjaxPane:function(){
			var v=this.$V;
			if(v.ajaxpane){
				xlv.sys.dispose(v.ajaxpane,true);
				v.ajaxpane=null;
			}
			if(Prototype.Browser.IE) Element.setStyle(this,{zIndex:''});
		},
		showPane:function(){
			var p=this.$P,v=this.$V;
			var call_loaded=((!p.ajaxPane)||(v.ajaxpane&&v.ajaxpane.isLoaded()));
			if(p.ajaxPane&&!v.ajaxpane){
				v.ajaxpane=xlv.sys.newInstance(v.pane,'ajaxPane',p.ajaxPane.properties,p.ajaxPane.method);
			}
			var activepane=(v.ajaxpane)?v.ajaxpane:v.pane;
			var memo=xlv.sys.createMemoObject({type:'active_changed',src:this,from:activepane,to:activepane});
			xlv.sys.broadcastMessage(this,memo);
			this._showPane();
			if(call_loaded)	{
				this._setModal(true);
				this.loadedPane();
			}
		},
		_showPane:function(){
			var v=this.$V;
			var align=this.$P.paneAlign;
			var dim=Element.getDimensions(v.pane);
			var parent=Element.getOffsetParent(v.pane);
			if(Prototype.Browser.IE && parent.tagName=='BODY') parent=this;//IE8
			var pdim=Element.getDimensions(parent);
			if(align=='center'&& parent!=this.getDesktop())align='middle';
			if(dim.width==0){
				aligh='left';
				v._redo_showPane=true;
			}
			var left,top=pdim.height;
			switch(align){
				case 'middle':
					left=(pdim.width-dim.width)/2;
					break;
				case 'right':
					left=pdim.width-dim.width;
					break;
				case 'center':
					left=(pdim.width-dim.width)/2;
					top=(pdim.height-dim.height)/2;
					break;
				case 'left':
				default:left=0;
			}
			var style={position:'absolute',display:'block','left':left+'px','top':top+'px',zIndex:this.$P.zIndex};
			v.save_zindex=this.$P.zIndex;
			Element.setStyle(this,{zIndex:this.$P.zIndex});
			Element.setStyle(v.pane,style);
		},
		_click:function(event){
			if(Element.hasClassName(this,'disabled'))return;
			if(event && xlv.util.isDescendantOf(event.target,this.$V.pane)) return;
			this.$super('xlv.obj.process._click',event);
		},
		process:function(options){
			var v=this.$V;
			if(Element.getStyle(v.pane,'display')=='none')this.showPane();
			else this.hidePane();
		}
	}
};
